import tornado.web
import sae.const
import tornado.database

class Connection(tornado.database.Connection):
    def __init__(self, host, database, user=None, password=None,
             max_idle_time=7 * 3600):
        super(Connection, self).__init__(
                                         host=host,
                                         database=database,
                                         user=user,
                                         password=password,
                                         max_idle_time = max_idle_time
                                         )
        self._db_args["init_command"] = 'SET time_zone = "+8:00"'
        try:
            self.reconnect()
        except Exception:
            logging.error("Cannot connect to MySQL on %s", self.host,
                          exc_info=True)

